/************************************************************
 *  * EaseMob CONFIDENTIAL
 * __________________
 * Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved.
 *
 * NOTICE: All information contained herein is, and remains
 * the property of EaseMob Technologies.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from EaseMob Technologies.
 */

#import "ChatGroupDetailViewController.h"
#import "ContactSelectionViewController.h"
#import "GroupSettingViewController.h"
#import "EMGroup.h"
#import "ContactView.h"
#import "GroupBansViewController.h"
#import "GroupSubjectChangingViewController.h"
#import "UIImageView+WebCache.h"
#import "TongXunLu.h"
#import "PeopleDataViewController.h"
#import "ReportDetailVC.h"
#import "TongXunLuViewController.h"
#import "GroupMemberListViewController.h"
#import "PointsManager.h"
#import "UIColor+Addition.h"

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

@interface ChatGroupDetailViewController ()<IChatManagerDelegate, EMChooseViewDelegate, UIActionSheetDelegate,UIAlertViewDelegate>

- (void)unregisterNotifications;
- (void)registerNotifications;

@property (nonatomic) GroupOccupantType occupantType;
@property (strong, nonatomic) EMGroup *chatGroup;

//@property (strong, nonatomic) NSMutableArray *dataSource;
@property (strong, nonatomic) UIScrollView *scrollView;
@property (strong, nonatomic) UIButton *addButton;
@property (strong, nonatomic) UIButton *delectButton;
@property (strong, nonatomic) UIView *footerView;
@property (strong, nonatomic) UIButton *clearButton;
@property (strong, nonatomic) UIButton *exitButton;
@property (strong, nonatomic) UIButton *dissolveButton;
@property (strong, nonatomic) UIButton *configureButton;
@property (strong, nonatomic) ContactView *selectedContact;
@property (strong, nonatomic) NSMutableArray *currentArray;
@property (strong,nonatomic) NSDictionary *huanXinDic;
@property (nonatomic,assign) BOOL isOwner,isEditing;
@property (strong, nonatomic) UISwitch *messageSwitch;
@property (nonatomic,assign) NSInteger currentArrayCount;

- (void)dissolveAction;
- (void)clearAction;
- (void)exitAction;
- (void)configureAction;

@end

@implementation ChatGroupDetailViewController

- (void)registerNotifications {
    [self unregisterNotifications];
    [[EaseMob sharedInstance].chatManager addDelegate:self delegateQueue:nil];
}

- (void)unregisterNotifications {
    [[EaseMob sharedInstance].chatManager removeDelegate:self];
}

- (void)dealloc {
    [self unregisterNotifications];
}

- (instancetype)initWithGroup:(EMGroup *)chatGroup
{
    self = [super init];
    if (self) {
        // Custom initialization
        _chatGroup = chatGroup;
        NSDictionary *loginInfo = [[[EaseMob sharedInstance] chatManager] loginInfo];
        NSString *loginUsername = [loginInfo objectForKey:kSDKUsername];
        //群组是否是自己创建的
        _isOwner = [chatGroup.owner isEqualToString:loginUsername];
        _isEditing=NO;
        //_dataSource = [NSMutableArray array];
        if (_isOwner) {
            _occupantType=GroupOccupantTypeOwner;
        }else{
            _occupantType = GroupOccupantTypeMember;
        }
        [self registerNotifications];
        //[self reloadDataSource];
        [self createListWithArray:_chatGroup.occupants];
    }
    return self;
}

- (instancetype)initWithGroupId:(NSString *)chatGroupId
{
    EMGroup *chatGroup = nil;
    NSArray *groupArray = [[EaseMob sharedInstance].chatManager groupList];
    for (EMGroup *group in groupArray) {
        
        if ([group.groupId isEqualToString:chatGroupId]) {
            
            chatGroup = group;
            _huanXinDic = [[NSUserDefaults standardUserDefaults]objectForKey:@"huanXinInfo"];
            break;
        }
    }
    
    if (chatGroup == nil) {
        [self showHint:NSLocalizedString(@"group.fetchInfoFail", @"failed to get the group details, please try again later")];
    }
    
    self = [self initWithGroup:chatGroup];
    if (self) {
        //
    }
    
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStyleGrouped];
    
    self.title=@"群介绍";
    
    UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 28, 28)];
    [backButton setImage:[UIImage imageNamed:@"regback01"] forState:UIControlStateNormal];
    [backButton addTarget:self.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
    backButton.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    [self.navigationItem setLeftBarButtonItem:backItem];
    
    _messageSwitch = [[UISwitch alloc] init];
    [_messageSwitch addTarget:self action:@selector(messageSwitchChanged:) forControlEvents:UIControlEventValueChanged];
    [_messageSwitch setOn:_chatGroup.isBlocked animated:YES];
    
    self.tableView.tableFooterView = self.footerView;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    if (self.isAddGroupMember) {
        //添加群成员
        [self showHudInView:self.view hint:NSLocalizedString(@"group.addingOccupant", @"add a group member...")];
        
        __weak typeof(self) weakSelf = self;
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSMutableArray *source = [NSMutableArray array];
            
            for (NSString *buddy in self.addmemberArray) {
                
                [source addObject:buddy];
            }
            
            EMError *error = nil;
            weakSelf.chatGroup = [[EaseMob sharedInstance].chatManager addOccupants:source toGroup:weakSelf.chatGroup.groupId welcomeMessage:nil error:&error];
            if (!error) {
                //[weakSelf reloadDataSource];
                [weakSelf createListWithArray:weakSelf.chatGroup.occupants];
            }
            else
            {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self hideHud];
                    [weakSelf showHint:NSLocalizedString(@"group.addOccupantFail", @"Failed to add group member, please try again later")];
                });
            }
        });
        
    }
    self.isAddGroupMember=NO;
    
    if (_currentArrayCount!=_currentArray.count) {
        [self reloadDataSource];
    }
}
//监听群组变化时刷新表
- (void)groupDidUpdateInfo:(EMGroup *)group error:(EMError *)error
{
    [self reloadDataSource];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

#pragma mark - getter

- (UIScrollView *)scrollView
{
    if (_scrollView == nil) {
        
        _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        _scrollView.tag = 0;
        
        _addButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,  0,  0)];
        [_addButton setImage:[UIImage imageNamed:@"group_participant_addHL"] forState:UIControlStateNormal];
        [_addButton addTarget:self action:@selector(addContact:) forControlEvents:UIControlEventTouchUpInside];
        
        _delectButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,  0,  0)];
        [_delectButton setImage:[UIImage imageNamed:@"delectgroup.png"] forState:UIControlStateNormal];
        [_delectButton addTarget:self action:@selector(delectGroup:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _scrollView;
}

- (UIButton *)clearButton
{
    if (_clearButton == nil) {
        _clearButton = [[UIButton alloc] init];
        [_clearButton setTitle:NSLocalizedString(@"group.removeAllMessages", @"remove all messages") forState:UIControlStateNormal];
        [_clearButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_clearButton addTarget:self action:@selector(clearAction) forControlEvents:UIControlEventTouchUpInside];
        [_clearButton setBackgroundColor:[UIColor colorWithRed:87 / 255.0 green:186 / 255.0 blue:205 / 255.0 alpha:1.0]];
    }
    
    return _clearButton;
}

- (UIButton *)dissolveButton
{
    if (_dissolveButton == nil) {
        _dissolveButton = [[UIButton alloc] init];
        [_dissolveButton setTitle:NSLocalizedString(@"group.destroy", @"dissolution of the group") forState:UIControlStateNormal];
        [_dissolveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _dissolveButton.layer.cornerRadius=3.0;
        [_dissolveButton addTarget:self action:@selector(dissolveAction) forControlEvents:UIControlEventTouchUpInside];
        [_dissolveButton setBackgroundColor: [UIColor colorWithRed:191 / 255.0 green:48 / 255.0 blue:49 / 255.0 alpha:1.0]];
    }
    
    return _dissolveButton;
}

- (UIButton *)exitButton
{
    if (_exitButton == nil) {
        _exitButton = [[UIButton alloc] init];
        [_exitButton setTitle:NSLocalizedString(@"group.leave", @"quit the group") forState:UIControlStateNormal];
        [_exitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _exitButton.layer.cornerRadius=3.0;
        [_exitButton addTarget:self action:@selector(exitAction) forControlEvents:UIControlEventTouchUpInside];
        [_exitButton setBackgroundColor:[UIColor colorWithRed:191 / 255.0 green:48 / 255.0 blue:49 / 255.0 alpha:1.0]];
    }
    
    return _exitButton;
}

- (UIView *)footerView
{
    if (_footerView == nil) {
        _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 80)];
        _footerView.backgroundColor = [UIColor clearColor];
        
        self.dissolveButton.frame = CGRectMake(20, 20, _footerView.frame.size.width - 40, 35);
        self.exitButton.frame = CGRectMake(20, 20, _footerView.frame.size.width - 40, 35);
    }
    
    return _footerView;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (section==0) {
        if (_currentArray.count>20) {
            return 2;
        }else{
            return 1;
        }
    }
    if (section==1) {
        
        if (_isOwner) {
            return 1;
        }else{
            return 2;
        }
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell =[tableView cellForRowAtIndexPath:indexPath];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }
    
    if (indexPath.section == 0) {
        if (indexPath.row==0) {
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            [cell.contentView addSubview:self.scrollView];
        }else{
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.textLabel.text=[NSString stringWithFormat:@"全部群成员(%lu)",_currentArray.count];
        }
        
    }
    else if (indexPath.section == 1)
    {
        if (indexPath.row==0) {
            cell.textLabel.text = @"群名称";
            
            if (_isOwner) {
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            }else{
                cell.accessoryType = UITableViewCellAccessoryNone;
            }
            cell.detailTextLabel.text = _chatGroup.groupSubject;
            
        }else{
            _messageSwitch.frame = CGRectMake(self.tableView.frame.size.width - (_messageSwitch.frame.size.width + 10), (cell.contentView.frame.size.height - _messageSwitch.frame.size.height) / 2, _messageSwitch.frame.size.width, _messageSwitch.frame.size.height);
            [cell.contentView addSubview:_messageSwitch];
            [cell.contentView bringSubviewToFront:_messageSwitch];
            
            cell.textLabel.text = @ "消息免打扰";
            cell.accessoryType = UITableViewCellAccessoryNone;
        }
        
    }
    else if (indexPath.section == 2)
    {
        cell.textLabel.text =@"清空聊天记录";
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    else if (indexPath.section == 3)
    {
        cell.textLabel.text =@"举报";
        //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    return cell;
}

#pragma mark - Table view delegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //int row = (int)indexPath.section;
    if ( indexPath.section== 0) {
        if (indexPath.row==0) {
            return self.scrollView.frame.size.height;
        }else{
            return 44;
        }
    }
    else {
        return 44;
    }
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section==0&&indexPath.row==1) {
        GroupMemberListViewController *groupVC=[[GroupMemberListViewController alloc]init];
        groupVC.groupListArray=_currentArray;
        groupVC.isGroupOwner=_isOwner;
        groupVC.groupId=_chatGroup.groupId;
        groupVC.groupOwner=_chatGroup.owner;
        NSLog(@"群组id：%@",_chatGroup.groupId);
        [self.navigationController pushViewController:groupVC animated:YES];
    }
    if (indexPath.section==1) {
        
        if (_isOwner) {
            GroupSubjectChangingViewController *changingController = [[GroupSubjectChangingViewController alloc] initWithGroup:_chatGroup];
            [self.navigationController pushViewController:changingController animated:YES];
        }
        
    }else if (indexPath.section==2){
        
        [self clearAction];
        
    }else if (indexPath.section==3){
        
        NSLog(@">>>>>>>>>>>>>%@",_chatGroup.groupId);
        ReportDetailVC *reportVC = [[ReportDetailVC alloc] init];
        reportVC.itemid =_chatGroup.groupId;
        reportVC.m_itemid = @"10";
        [self.navigationController pushViewController:reportVC animated:YES];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 15;
}
/*
 #pragma mark - data
 
 - (void)fetchGroupInfo
 {
 __weak typeof(self) weakSelf = self;
 
 [[EaseMob sharedInstance].chatManager asyncFetchGroupInfo:_chatGroup.groupId completion:^(EMGroup *group, EMError *error) {
 dispatch_async(dispatch_get_main_queue(), ^{
 
 if (!error) {
 weakSelf.chatGroup = group;
 
 [weakSelf createListWithArray:_chatGroup.occupants];
 }
 else{
 
 }
 });
 } onQueue:nil];
 }
 */
-(void)createListWithArray:(NSArray *)arr{
    
    _currentArray=[[NSMutableArray alloc]init];
    for (NSString *str in arr) {
        
        if ([_huanXinDic objectForKey:[NSString stringWithFormat:@"%@name",str]]) {
            TongXunLu *user=[[TongXunLu alloc]init];
            user.huanxin_username=str;
            user.truename=[_huanXinDic objectForKey:[NSString stringWithFormat:@"%@name",str]];
            user.pic=[_huanXinDic objectForKey:[NSString stringWithFormat:@"%@pic",str]];
            NSString *useridString=[_huanXinDic objectForKey:[NSString stringWithFormat:@"%@userid",str]];
            user.userid=[useridString intValue];
            [_currentArray addObject:user];
        }
        
    }
    _currentArrayCount=_currentArray.count;
    [self reloadDataSource];
}

- (void)reloadDataSource
{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [self refreshScrollView];
        [self refreshFooterView];
        [self hideHud];
    });
}

- (void)refreshScrollView
{
    [self.scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    [self.addButton removeFromSuperview];
    [self.delectButton removeFromSuperview];
    
    float headImgWidth=50*(SCREEN_WIDTH/320);
    int rowCount=SCREEN_WIDTH>375?5:4;
    float gapWidth=(SCREEN_WIDTH-headImgWidth*rowCount)/(rowCount+1);
    NSInteger count=_currentArray.count>20?20:_currentArray.count;
    [self changeScrollerViewFrameWithCount:count andRowCount:rowCount andImgWidth:headImgWidth];
    
    for (int i=0; i<count; i++) {
        
        TongXunLu *user=[_currentArray objectAtIndex:i];
        ContactView *contactView = [[ContactView alloc] initWithFrame:CGRectMake(gapWidth+(gapWidth+headImgWidth)*(i%rowCount),20+(headImgWidth+45)*(i/rowCount),headImgWidth,headImgWidth)];
        //contactView.index=i;
        //contactView.backgroundColor=[UIColor yellowColor];
        contactView.headImgView.layer.cornerRadius = headImgWidth/2.0;
        contactView.headImgView.clipsToBounds = YES;
        [contactView.headImgView setImageWithURL:[NSURL URLWithString:user.pic] placeholderImage:[UIImage imageNamed:@"default_touxiang"]];
        contactView.remark = user.truename;
        contactView.tag=i+1000;
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(lookInfo:)];
        [contactView addGestureRecognizer:tap];
        [self.scrollView addSubview:contactView];
        
        UILabel *nameLabel=[[UILabel alloc]initWithFrame:CGRectMake(gapWidth+(gapWidth+headImgWidth)*(i%rowCount),25+headImgWidth+(headImgWidth+45)*(i/rowCount),headImgWidth,25)];
        nameLabel.text=user.truename;
        nameLabel.textAlignment=1;
        nameLabel.font=[UIFont systemFontOfSize:14];
        nameLabel.textColor=[UIColor convertHexColorToUIColor:0x333333];
        //nameLabel.backgroundColor=[UIColor greenColor];
        [self.scrollView addSubview:nameLabel];
    }
    
    self.addButton.frame = CGRectMake(gapWidth+(gapWidth+headImgWidth)*(count%rowCount),23+(headImgWidth+45)*(count/rowCount),headImgWidth-6,headImgWidth-6);
    [self.scrollView addSubview:self.addButton];
    
    if (_isOwner) {
        self.delectButton.frame = CGRectMake(gapWidth+(gapWidth+headImgWidth)*((count+1)%rowCount),23+(headImgWidth+45)*((count+1)/rowCount),headImgWidth-6,headImgWidth-6);
        [self.scrollView addSubview:self.delectButton];
    }
    
    [self.tableView reloadData];
}

-(void)changeScrollerViewFrameWithCount:(NSInteger)count  andRowCount:(NSInteger)rowCount andImgWidth:(float)width{
    
    if (_isOwner) {
        count=count+2;
    }else{
        count=count+1;
    }
    NSInteger row=(count+rowCount-1)/rowCount;
    self.scrollView.frame = CGRectMake(0, 0, SCREEN_WIDTH,row*(width+45)+20);
}

- (void)refreshFooterView
{
    if (self.occupantType == GroupOccupantTypeOwner) {
        [_exitButton removeFromSuperview];
        [_footerView addSubview:self.dissolveButton];
    }
    else{
        [_dissolveButton removeFromSuperview];
        [_footerView addSubview:self.exitButton];
    }
}

//点击头像查看群成员详细信息
-(void)lookInfo:(UITapGestureRecognizer *)clickPress{
    
    TongXunLu *userInfo=[_currentArray objectAtIndex:clickPress.view.tag-1000];
    PeopleDataViewController *peopleVC=[[PeopleDataViewController alloc]init];
    peopleVC.touserid=[NSString stringWithFormat:@"%d",userInfo.userid];
    [self.navigationController pushViewController:peopleVC animated:YES];
}

//添加成员
- (void)addContact:(id)sender
{
    TongXunLuViewController *addVC=[[TongXunLuViewController alloc]init];
    addVC.orAddGroupMember=YES;
    addVC.groupArray=self.currentArray;
    addVC.orRefresh=YES;
    [self.navigationController pushViewController:addVC animated:YES];
}

//清空聊天记录
- (void)clearAction
{
    __weak typeof(self) weakSelf = self;
    [EMAlertView showAlertWithTitle:NSLocalizedString(@"prompt", @"Prompt")
                            message:@"确定清空聊天记录?"
                    completionBlock:^(NSUInteger buttonIndex, EMAlertView *alertView) {
                        if (buttonIndex == 1) {
                            [[NSNotificationCenter defaultCenter] postNotificationName:@"RemoveAllMessages" object:weakSelf.chatGroup.groupId];
                        }
                    } cancelButtonTitle:NSLocalizedString(@"cancel", @"Cancel")
                  otherButtonTitles:NSLocalizedString(@"ok", @"OK"), nil];
    
}

//解散群组
- (void)dissolveAction
{
    __weak typeof(self) weakSelf = self;
    [self showHudInView:self.view hint:NSLocalizedString(@"group.destroy", @"dissolution of the group")];
    [[EaseMob sharedInstance].chatManager asyncDestroyGroup:_chatGroup.groupId completion:^(EMGroup *group, EMGroupLeaveReason reason, EMError *error) {
        [weakSelf hideHud];
        if (error) {
            [weakSelf showHint:NSLocalizedString(@"group.destroyFail", @"dissolution of group failure")];
        }
        else{
            [[NSNotificationCenter defaultCenter] postNotificationName:@"ExitGroup" object:nil];
        }
    } onQueue:nil];
    
    //    [[EaseMob sharedInstance].chatManager asyncLeaveGroup:_chatGroup.groupId];
}

//设置群组
- (void)configureAction {
    // todo
    [[[EaseMob sharedInstance] chatManager] asyncIgnoreGroupPushNotification:_chatGroup.groupId
                                                                    isIgnore:_chatGroup.isPushNotificationEnabled];
    
    return;
    
}

//退出群组
- (void)exitAction
{
    __weak typeof(self) weakSelf = self;
    [self showHudInView:self.view hint:NSLocalizedString(@"group.leave", @"quit the group")];
    [[EaseMob sharedInstance].chatManager asyncLeaveGroup:_chatGroup.groupId completion:^(EMGroup *group, EMGroupLeaveReason reason, EMError *error) {
        [weakSelf hideHud];
        if (error) {
            [weakSelf showHint:NSLocalizedString(@"group.leaveFail", @"exit the group failure")];
        }
        else{
            [[NSNotificationCenter defaultCenter] postNotificationName:@"ExitGroup" object:nil];
        }
    } onQueue:nil];
    
    //    [[EaseMob sharedInstance].chatManager asyncLeaveGroup:_chatGroup.groupId];
}

- (void)didIgnoreGroupPushNotification:(NSArray *)ignoredGroupList error:(EMError *)error {
    // todo
    NSLog(@"ignored group list:%@.", ignoredGroupList);
}

- (void)messageSwitchChanged:(id)sender
{
    
    {
        if (_messageSwitch.isOn != _chatGroup.isBlocked) {
            __weak typeof(self) weakSelf = self;
            //[self showHudInView:self.view hint:NSLocalizedString(@"group.setting.save", @"set properties")];
            [self showHudInView:self.view hint:@"设置中..."];
            if (_messageSwitch.isOn) {
                [[EaseMob sharedInstance].chatManager asyncBlockGroup:_chatGroup.groupId completion:^(EMGroup *group, EMError *error) {
                    [weakSelf hideHud];
                    [weakSelf showHint:NSLocalizedString(@"group.setting.success", @"set success")];
                } onQueue:nil];
            }
            else{
                [[EaseMob sharedInstance].chatManager asyncUnblockGroup:_chatGroup.groupId completion:^(EMGroup *group, EMError *error) {
                    [weakSelf hideHud];
                    [weakSelf showHint:NSLocalizedString(@"group.setting.success", @"set success")];
                } onQueue:nil];
            }
        }
        
    }
}

-(void)delectGroup:(UIButton *)btn{
    
    GroupMemberListViewController *groupVC=[[GroupMemberListViewController alloc]init];
    groupVC.groupListArray=_currentArray;
    groupVC.isGroupOwner=_isOwner;
    groupVC.groupId=_chatGroup.groupId;
    groupVC.groupOwner=_chatGroup.owner;
    [self.navigationController pushViewController:groupVC animated:YES];
}

@end
